library(survival)
library(penalized)
expr<-read.table("temp_input",sep="\t",head=T)
#expr<-read.table("input_expr",sep="\t",head=T)
ref<-read.table("/data1/bsi/BORA_processing/devel/eqtl/parallelize_genotypingsurvival/result_ref_file",sep="\t")
rownames(ref)<-ref[,1]
expr1<-merge(ref,expr,by="row.names",all.x=F)
geno<-read.table("/data1/bsi/BORA_processing/devel/eqtl/pinalized/input_withcorrecthead.tped",sep=" ",head=T)
rownames(geno)<-geno[,2]
i<-1
#clin<-read.delim("/data1/bsi/BORA_processing/devel/eqtl/parallelize_genotypingsurvival/clinical" ,sep="\t",quote="\"",dec=".",fill=TRUE,comment.char="",header=TRUE,col.names=c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE"),as.is=c(TRUE,TRUE,FALSE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE),colClasses=c("character","numeric","factor","numeric","numeric","numeric","integer","integer","integer","factor"))
clin<-read.delim("/data1/bsi/BORA_processing/devel/eqtl/pinalized/clinical" ,sep="\t",quote="\"",dec=".",fill=TRUE,comment.char="",header=TRUE,col.names=c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","ClVerhaakPub"),as.is=c(TRUE,TRUE,FALSE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,TRUE),colClasses=c("character","numeric","factor","numeric","numeric","numeric","integer","integer","integer","factor","factor"))
clin$SUBJECT<-gsub("-",".",clin$SUBJECT)
AUCrank<-c()
rownames(expr1)<- expr1[,1]
rownames(clin)<-clin[,1]
gg<-t(expr1[1,])
rownames(gg)<-colnames(expr1)
colnames(gg)<-c("gene")
nn<-ncol(clin)+4
i
l1<-expr1[i,4]-20000
l2<-expr1[i,4]+20000
l3<-expr1[i,3]
index<-c()
index<-which(geno[,4]>=l1 & geno[,4]<l2  & geno[,1] == l3)
geno1<-geno[index,]
geno2<-t(geno1)
rownames(geno2)<-colnames(geno1)
colnames(geno2)<-rownames(geno1)
write.table(geno2,"geno2.txt",quote=FALSE,sep="\t",col.names=TRUE,row.names=TRUE)
geno1<-geno[index,]
geno2<-t(geno1)
rownames(geno2)<-colnames(geno1)
colnames(geno2)<-rownames(geno1)
rownames(clin)<-clin[,1]
merge1<-merge(clin,geno2,by="row.names",all.x=F)
rownames(merge1)<-merge1[,1]
merge2<-merge(gg,merge1,by="row.names",all.x=F)
colnames_merge2<-colnames(merge2)
vec<-paste(colnames_merge2[nn:length(colnames_merge2)], collapse = "+")
K<-parse(text=paste("Surv(OS,ALIVEOS)~gene",paste(colnames_merge2[nn:length(colnames_merge2)], collapse = "+"),sep="+"))
K
getwd()
optL2 (eval(K), unpenalized=merge2[,5],data=merge2,model ="cox")
K<-parse(text=paste("gene",paste(colnames_merge2[nn:length(colnames_merge2)], collapse = "+"),sep="+"))
K
optL2 (Surv(OS,ALIVEOS), penalized=gene+rs4865919,unpenalized=AGE,data=merge2,model ="cox")
optL2 (Surv(OS,ALIVEOS), penalized=merge2[,15:16],data=merge2,model ="cox")
attach(nki70
)
attach(merge2)
optL2 (Surv(OS,ALIVEOS), penalized=merge2[,15:16],data=merge2,model ="cox")
optL2 (Surv(OS,ALIVEOS), penalized=gene+rs4865919,unpenalized=AGE,data=merge2,model ="cox")
optL1(Surv(OS,ALIVEOS), penalized=gene+rs4865919,unpenalized=AGE,data=merge2,model ="cox")
optL2 (Surv(OS,ALIVEOS), merge2[,15:16],data=merge2,model ="cox")
optL1(Surv(OS,ALIVEOS), merge2[,15:16],data=merge2,model ="cox")
is.data.frame(merge2)
is.matrix(merge2)
optL2 (Surv(OS,ALIVEOS), penalized=as.matrix(merge2[,15:16]),data=merge2,model ="cox")
k<-as.matrix(merge2[,15:16])
optL2 (Surv(OS,ALIVEOS), penalized=k,data=merge2,model ="cox")
k[1,]
optL1(Surv(OS,ALIVEOS), penalized=~gene+rs4865919,unpenalized=~AGE,data=merge2,model ="cox")
colnames9clin)
colnames(clin)
optL1(Surv(OS,ALIVEOS), penalized=~gene+rs4865919,unpenalized=~AGE+ClVerhaakPub,data=merge2,model ="cox")
optL2(Surv(OS,ALIVEOS), penalized=~gene+rs4865919,unpenalized=~AGE+ClVerhaakPub,data=merge2,model ="cox")
K
K<-parse(text=paste("gene",paste(colnames_merge2[nn:nn+1], collapse = "+"),sep="+"))
K
optL2(Surv(OS,ALIVEOS), penalized=eval(K),unpenalized=~AGE+ClVerhaakPub,data=merge2,model ="cox")
K<-parse(text=paste("~gene",paste(colnames_merge2[nn:nn+1], collapse = "+"),sep="+"))
optL2(Surv(OS,ALIVEOS), penalized=eval(K),unpenalized=~AGE+ClVerhaakPub,data=merge2,model ="cox")
geno1<-geno[index,]
geno2<-t(geno1)
rownames(geno2)<-colnames(geno1)
colnames(geno2)<-rownames(geno1)
rownames(clin)<-clin[,1]
merge1<-merge(clin,geno2,by="row.names",all.x=F)
rownames(merge1)<-merge1[,1]
merge2<-merge(gg,merge1,by="row.names",all.x=F)
colnames_merge2<-colnames(merge2)
vec<-paste(colnames_merge2[nn:length(colnames_merge2)], collapse = "+")
K<-parse(text=paste("~gene",paste(colnames_merge2[nn:length(colnames_merge2)], collapse = "+"),sep="+"))
K
optL2(Surv(OS,ALIVEOS), penalized=eval(K),unpenalized=~AGE+ClVerhaakPub,data=merge2,model ="cox")
topsnp<-geno["rs2456223",]
topsnp[1:5]
getwd()
expr<-read.table("input_expr",sep="\t",head=T)
expr<-read.table("../input_expr",sep="\t",head=T)
expr1<-merge(ref,expr,by="row.names",all.x=F)
dim(expr1)
expr1[1,1:10]
expr1[1:3,1:4]
which(expr1[2]==11338)
topgene<-expr1[1056,]
topgene[1:4]
which(expr1[2]==11319)
topgenesnp<-expr1[1038,]
topgenesnp[1:4]
topsnp<-t(geno1)
dim(topsnp)
topsnp[1,]
topsnp[2,]
topsnp<-geno["rs2456223",]
which(expr1[2]==7075)
topsnpgene<-expr1[8881,]
topsnp<-t(topsnp)
dim(topsnp)
topsnp<-geno["rs3806402",]
rownames(topsnp)<-topsnp[,2]
topsnp[1,1:2]
colnames(topsnp)<-colnames(topsnp)
merge1<-merge(clin,geno2,by="row.names",all.x=F)
dim(merge1)
merge1<-merge(clin,topsnp,by="row.names",all.x=F)
dim(merge1)
topsnp<-t(topsnp)
topsnp<-geno["rs3806402",]
rownames(topsnp)<-topsnp[,2]
colnames(topsnp)<-colnames(geno)
topsnp1<-t(topsnp)
rownames(topsnp1)<-colnames(topsnp)
colnames(topsnp1)<-rownames(topsnp)
merge1<-merge(clin,topsnp,by="row.names",all.x=F)
dim(merge1)
rownames(topsnp1)1:5
rownames(topsnp1)$1:5
rownames(topsnp1)
rownames(topsnp1)1:5
rownames(topsnp1)[1:5]
rownames(clin)[1:5]
merge1<-merge(clin,topsnp1,by="row.names",all.x=F)
dim(merge1)
merge1[1,]
optL2(Surv(OS,ALIVEOS), penalized=~rs3806402,unpenalized=~AGE+ClVerhaakPub,data=merge1,model ="cox")
opt1<-optL1 (Surv(OS,ALIVEOS), penalized=~rs3806402,unpenalized=~AGE+ClVerhaakPub,data=merge1,model ="cox",minlambda1=0.2*27.44, maxlambda1=5*27.44)
fit<-cvl(Surv(OS,ALIVEOS), penalized=~rs3806402,unpenalized=~AGE+ClVerhaakPub,data=merge1,model ="cox",lambda1=opt1$lambda,fold=20)
fit
summary( fit)
Survival_probs<-survival(fit$predictions,median(merge1$OS)
)
order_rank<-order(Survival_probs)
sorted_ranks<-seq(1,length(order_rank),1)
order_of_index<-order(order_rank)
wanted_ranks<-sorted_ranks[order_of_index]
wr1<-matrix(nrow=1, ncol=length(wanted_ranks))
colnames(wr1)<-merge2[,1]
wr1[1,]<-wanted_ranks
colnames(wr1)<-merge1[,1]
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
dim(dt)
dt[1,]
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","RANK")
surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
AUC<-surv$concordance
dt[1,]
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","CLASSI","RANK")
surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
AUC<-surv$concordance
AUC
getwd()
savehistory("u.R")
topgene[1:5]
dim(gg)
Survival_Probs
Survival_probs
Survival_probs[1:10]
rrk<-rank(Survival_probs)
rrk[1:10]
rrk<-length(Survival_probs)+1-rank(Survival_probs)
rrk[1:10]
order_rank<-order(Survival_probs)
sorted_ranks<-seq(1,length(order_rank),1)
order_of_index<-order(order_rank)
wanted_ranks<-sorted_ranks[order_of_index]
wanted_ranks[1:10]
wanted_ranks<- length(Survival_probs)+1-sorted_ranks[order_of_index]
wanted_ranks[1:10]
wr1<-matrix(nrow=1, ncol=length(wanted_ranks))
colnames(wr1)<-merge2[,1]
wr1[1,]<-wanted_ranks
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","RANK")
surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","RANK")
colnames(dt)
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","CLUSTERID","RANK")
colnames(dt)
surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
AUC<-surv$concordance
AUC
summary(fit)
summary(fit$fullfit)
fit$fullfit
print(fit$fullfit)
head(fit$fullfit)
head(fit$fullfit)
summary(fit)
summary(fit$predictions)
fit$predictions
fit$cvl
fit$cvls
sum(fit$cvls)
fit$fold
fit
fit$fullfit[0]
coefficients(fit$fullfit)
opt2<-optL2(Surv(OS,ALIVEOS), penalized=~rs3806402,unpenalized=~AGE,data=merge1,model ="cox")
opt1<-optL1(Surv(OS,ALIVEOS), penalized=~rs3806402,unpenalized=~AGE,data=merge1,model ="cox",minlambda1=0.2*opt2$lambda, maxlambda1=5*opt2$lambda)
fit<-cvl(Surv(OS,ALIVEOS), penalized=~rs3806402,unpenalized=~AGE,data=merge1,model ="cox",lambda1=opt1$lambda,fold=20)
Survival_probs<-survival(fit$predictions,median(merge1$OS))
Survival_probs[1:10]
order_rank<-order(Survival_probs)
sorted_ranks<-seq(1,length(order_rank),1)
order_of_index<-order(order_rank)
wanted_ranks<-sorted_ranks[order_of_index]
wr1<-matrix(nrow=1, ncol=length(wanted_ranks))
colnames(wr1)<-merge2[,1]
wr1[1,]<-wanted_ranks
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
colnames(wr1)<-merge1[,1]
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
dim(dt)
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","ClVerhaakPub","RANK")
surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
AUC<-surv$concordance
AUC
wr1[1,]
opt2<-optL2(Surv(OS,ALIVEOS), penalized=~rs3806402,data=merge1,model ="cox")
opt1<-optL1(Surv(OS,ALIVEOS), penalized=~rs3806402,data=merge1,model ="cox",minlambda1=0.2*opt2$lambda, maxlambda1=5*opt2$lambda)
fit<-cvl(Surv(OS,ALIVEOS), penalized=~rs3806402,data=merge1,model ="cox",lambda1=opt1$lambda,fold=20)
Survival_probs<-survival(fit$predictions,median(merge1$OS))
order_rank<-order(Survival_probs)
sorted_ranks<-seq(1,length(order_rank),1)
order_of_index<-order(order_rank)
wanted_ranks<-sorted_ranks[order_of_index]
wr1<-matrix(nrow=1, ncol=length(wanted_ranks))
colnames(wr1)<-merge1[,1]
wr1[1,]<-wanted_ranks
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","Cal","RANK")
surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
AUC<-surv$concordance
AUC
 dt$RANK[1:5]
ls.vars <-function(env=sys.frame(-1))unlist(lapply(ls(env=env),function(x)if(!is.function(get(x)))x))
ls.vars
ls.vars()
topsnpgene
opt2<-optL2(Surv(OS,ALIVEOS), penalized=~rs3806402,unpenalized=~AGE,data=merge1,model ="cox")
opt1<-optL1(Surv(OS,ALIVEOS), penalized=~rs3806402,unpenalized=~AGE,data=merge1,model ="cox",minlambda1=0.2*opt2$lambda, maxlambda1=5*opt2$lambda)
fit<-cvl(Surv(OS,ALIVEOS), penalized=~rs3806402,unpenalized=~AGE,data=merge1,model ="cox",lambda1=opt1$lambda,fold=20)
Survival_probs<-survival(fit$predictions,median(merge1$OS))
wanted_ranks<-rank(Survival_probs)
wanted_ranks[1:5]
order_rank<-order(Survival_probs)
sorted_ranks<-seq(1,length(order_rank),1)
order_of_index<-order(order_rank)
wanted_ranks<-sorted_ranks[order_of_index]
wanted_ranks[1:5]
wr1<-matrix(nrow=1, ncol=length(wanted_ranks))
colnames(wr1)<-merge1[,1]
wr1[1,]<-wanted_ranks
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","Cal","RANK")
surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
AUC<-surv$concordance
AUC
wanted_ranks<-length(Survival_probs)-(rank(Survival_probs)
)
wr1<-matrix(nrow=1, ncol=length(wanted_ranks))
colnames(wr1)<-merge1[,1]
wr1[1,]<-wanted_ranks
dt <- merge(clin,t(wr1),by.y="row.names",by.x="SUBJECT")
colnames(dt) <- c("SUBJECT","AGE","GENDER","OS","PFS","DFS","ALIVEOS","ALIVEPFS","ALIVEDFS","SITE","Cal","RANK")
surv<-survConcordance(Surv(OS,ALIVEOS)~RANK,data=dt)
AUC<-surv$concordance
AUC
which(Survival_probs=min(Survival_probs))
min(Survival_probs)
which(Survival_probs=0.5161025)
which(Survival_probs==0.5161025)
dim(Survival_probs)
length(Survival_probs)
which(Survival_probs==0.5161025)
kk<-t(Survival_probs)
dim(kk)
kk<-t(kk[1,]==0.5161025)
kk<-t(t(Survival_probs))
dim(kk)
which(kk[,1]==0.5161025)
which.min(kk)
which.min(Survival_probs)
wanted_ranks[107]
wanted_ranks<-rank(Survival_probs)
wanted_ranks[107]
which.max(Survival_probs)
wanted_ranks[96]
which.min(Survival_probs)
fit
savehistory("u.R")
